<template>
	<zh-app style="font-family: '阿里巴巴普惠体'">
		<zh-navbar title="一键报名" color="#85a5ff" linear="right" />
		<zh-spin :load="data.loading" tip="智能匹配中，请耐心等候">
			<zh-result
				v-if="data.showError"
				btnText="返回"
				:title="data.tipMsg.title"
				:subTitle="data.tipMsg.subTitle"
				@click="goBack"
			></zh-result>
			<view v-if="!data.showError">
				<zh-sheet v-if="!studentInfo.canEnrollFlag" :round="5" :margin="[30, 30,30,0]" :padding="[20,20]"  text color="primary">
					<zh-text class="text-weight-b" label="温馨提示:"></zh-text>
					<zh-text style="text-indent: 2em;padding-top:10rpx" >您目前没有取得<span style="color: red;">东阳市公安局核发的处于有效期内的《浙江省居住证》</span>，不符合东阳义务段学校新生报名最低条件</zh-text>
					<zh-text style="text-indent: 2em;padding-top:10rpx"  color="red"  label="若信息有误，请致电相关学校。"></zh-text>
				</zh-sheet>
				<zh-result
					v-if="studentInfo.canEnrollFlag&&studentInfo.bmFlag"
					btnText="前往"
					title="已报名"
					subTitle="可前往我的报名查看结果"
					@click="gotoMy"
				></zh-result>
				<view v-if="studentInfo.canEnrollFlag&&!studentInfo.bmFlag">
					<zh-sheet v-if="studentInfo.enrollBeforeList&&studentInfo.enrollBeforeList.length>0" :round="5" :margin="[30, 30,30,0]" :padding="[20,20]" color="primary" text>
						<zh-text class="text-weight-b" label="温馨提示:"></zh-text>
						<zh-text style="text-indent: 2em;padding-top:10rpx" label="根据您的条件以及相关学校的招生要求，您具备以下学校的报名资格 ，您可选择其中一所报名。"></zh-text>
						<zh-text style="text-indent: 2em;padding-top:10rpx" color="red" label="若信息匹配有误，请致电相关学校。"></zh-text>
					</zh-sheet>
					<zh-sheet v-else :round="5" :margin="[30, 30,30,0]" :padding="[20,20]" color="primary" text>
						<zh-text class="text-weight-b" label="温馨提示:"></zh-text>
						<zh-text style="text-indent: 2em;padding-top:10rpx" label="根据您的条件以及相关学校的招生要求，未匹配到公办学校A、B、C、特殊户口类报名资格。"></zh-text>
						<zh-text style="text-indent: 2em;padding-top:10rpx" color="red" label="若匹配有误，请致电相关学校。"></zh-text>
						<view class="flex-row-center-center">
							<zh-text style="text-indent: 2em;padding-top:10rpx">若匹配无误，</zh-text>
							<zh-tag :followTheme="false"  size="n" @click="gotoChooseSchool" label="选择其他学校报名"></zh-tag>
						</view>
					</zh-sheet>
					<z-paging
						
						ref="paging"
						:fixed="false"
						height="80vh"
						@query="onQueryList"
						v-model="data.bmList"
						:show-scrollbar="false"
					>
						<template v-slot:empty>
							<zh-result
								:showBtn="true"
								title="未匹配到信息"
								subTitle="请前往选择学校报名"
								btnText="前往"
								@click="gotoChooseSchool"
							></zh-result>
						</template>
						<z-paging-cell
							v-for="(item, index) in data.bmList"
							:key="item.enrollBeforeId"
						>
							<zh-card
								:margin="[30,30]"
								:color="getColor(item)" 
								text
							>
								<template v-slot:title>
									<view  style="width: 100%;" class="flex-row-center-between">
										<view :style="{'border-left': '10rpx solid ' +getColor(item)}">
										<zh-text  :fontSize="30" class="text-weight-b pl-10" :label="item.schoolName"></zh-text>
										</view>
										<zh-tag :followTheme="false" v-if="item.configTypeName!=='直升'" :color="getColor(item)" size="n" :label="item.specialFlag==='1'?'特殊通道':item.configName"></zh-tag>
									</view >
								</template>
								<template v-slot:content>
									<zh-desc v-if="item.specialFlag==='1'" prefixLabel="特殊通道类别" :prefixWidth="300"   v-model="item.configName" ></zh-desc>
									<view v-if="item.specialFlag!=='1'&&item.configTypeName!=='直升'">
									<zh-desc prefixLabel="户籍地址" :prefixWidth="200" v-model="item.householdAdress" placeholder="学区内无户籍"></zh-desc>
									<zh-desc prefixLabel="不动产权证" :prefixWidth="220" v-model="item.realPropertyDetails" placeholder="学区内无房产"></zh-desc>
									<zh-desc prefixLabel="房产地址" :prefixWidth="200" v-model="item.houseAdreess" placeholder="学区内无房产"></zh-desc>
									</view>
									<zh-desc v-if="item.specialFlag!=='1'&&item.configTypeName==='直升'" prefixLabel="报名类别" :prefixWidth="300"   v-model="item.configTypeName" ></zh-desc>
									<zh-button block label="我要报名" @click="onBmClick(item)" :color="getColor(item)" :followTheme="false"></zh-button>
								</template>
							</zh-card>
						</z-paging-cell>
						<z-paging-cell  v-if="data.bmList&&data.bmList.length>0">
						<zh-sheet :shadow="2" :round="6" :margin="[30, 30,30,0]" :padding="[20,20]"  text color="primary">
							<view class="flex-row-center-center">
							<zh-text color="red" class="text-weight-b">放弃以上学校，</zh-text>
							<zh-tag :followTheme="false"  size="n" @click="gotoChooseSchool" label="选择其他学校报名"></zh-tag>
							</view>
						</zh-sheet>
						</z-paging-cell>
						
					</z-paging>
					
				</view>
			</view>
		</zh-spin>
		
	</zh-app>
</template>

<script lang="ts" setup>
	//一键报名列表
	import {ref, reactive, onMounted} from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	//-------------内部参数---------------------------
	const data = reactive({
		loading:false,//加载数据
		showError:false,//是否显示异常
		tipMsg:{title:'数据异常',subTitle:'未传入学生信息'},//显示异常提示
		studentEnrollPreId:'',//预采集id
		bmList:[] as any,//可一键报名列表
		qbFlag:false,//是否抢报
	})
	const studentInfo=ref<any>({});//学生数据
	let paging=ref();//分页组件
	// 初始化
	onLoad((options:any) => {
		if(options.studentEnrollPreId){
			data.studentEnrollPreId=options.studentEnrollPreId
			getStudentInfo()
		}else{
			data.showError=true
		}
	})
	//------------内部方法---------------------
	const goBack=()=>{
		$router.back(1)
	}
	const getStudentInfo=()=>{
		//获取学生信息详情
		data.loading=true
		const params={studentEnrollPreId:data.studentEnrollPreId}
		$api.common.send.post("eduStudentEnroll0028", params).then((res: any) => {
			let result=Object.assign({},res.result||{})
			studentInfo.value=result
			data.qbFlag=result.qbFlag
			if(result.qbFlag){
				replaceChooseSchool()
			}
			data.showError=false
			data.loading=false
			paging.value?.reload()
		}).catch((err:any)=>{
			data.tipMsg.title="系统提示"
			data.tipMsg.subTitle=err.message
			data.showError=true
			data.loading=false
		})
	}
	const onQueryList = (pageNo:number, pageSize:number) => {
		//获取可报名信息，前端分页加载
		let enrollBeforeList=studentInfo.value.enrollBeforeList
		if(!enrollBeforeList){
			return
		}
		let list=enrollBeforeList.slice((pageNo-1)*pageSize,pageNo*pageSize)
		if(list&&list.length>0){
			paging.value?.complete(list)
		}else{
			paging.value?.complete(false)
		}
	}
	const getColor=(item:any)=>{
		if(item.specialFlag==='1'){
			return '#4ec752'
		}
		if(item.configName==="A"){
			return '#9C27B0'
		}else if(item.configName==="B"){
			return '#ffa114'
		}else if(item.configName==="C"){
			return '#3B5CF0'
		}else if(item.configName==="特殊户口"){
			return '#607D8B'
		}
	}
	const gotoChooseSchool=()=>{
		//跳转到选择其他学校
		$router.push('/pages/edu/enroll/schoolSelect',{studentEnrollPreId:data.studentEnrollPreId,schoolCategory:studentInfo.value.schoolCategory})
	}
	const replaceChooseSchool=()=>{
		//跳转到选择其他学校
		$router.replace('/pages/edu/enroll/schoolSelect',{studentEnrollPreId:data.studentEnrollPreId,schoolCategory:studentInfo.value.schoolCategory})
	}
	const onBmClick=(item:any)=>{
		$router.replace('/pages/edu/enroll/enrollForm',{studentEnrollPreId:data.studentEnrollPreId,schoolId:item.schoolId,enrollBeforeId:item.enrollBeforeId+''})
	}
	const gotoMy=()=>{
		//前往我的报名
		$router.replace('/pages/edu/enroll/myEnroll',{})
	}
</script>

<style lang="scss" scoped>
</style>